package com.zatech.cgnci.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zatech.cgnci.project.base.context.UserContext;
import com.zatech.cgnci.project.base.utils.VerifyUtils;
import com.zatech.cgnci.project.dto.CgnciRiskQueryDTO;
import com.zatech.cgnci.project.entity.UserEntity;
import com.zatech.cgnci.project.service.CgnciRiskService;
import com.zatech.cgnci.project.vo.CgnciRiskClassVO;
import com.zatech.cgnci.project.vo.CgnciRiskSubTypeVO;
import com.zatech.cgnci.project.vo.CgnciRiskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 险种接口
 *
 * @author user
 */

@RestController
@RequestMapping("/api/risk")
@RequiredArgsConstructor
@Api(produces = "application/json", tags = "险种api接口文档")
public class CgnciRiskController {

    private final CgnciRiskService riskService;

    @PostMapping("/page")
    @ApiOperation(value = "分页列表查询")
    public IPage<CgnciRiskVO> page(@RequestBody CgnciRiskQueryDTO riskQueryDTO) {
        UserEntity user = UserContext.getUser();
        if(VerifyUtils.isEmpty(user)){
            return null;
        }
        return riskService.pageRisk(riskQueryDTO);
    }

    @GetMapping("/listRiskClass")
    @ApiOperation(value = "获取险类下拉")
    public List<CgnciRiskClassVO> listRiskClass() {
        UserEntity user = UserContext.getUser();
        if(VerifyUtils.isEmpty(user)){
            return null;
        }
        return riskService.listRiskClass();
    }

    @GetMapping("/listRiskSubType")
    @ApiOperation(value = "获取险种下拉")
    public List<CgnciRiskSubTypeVO> listRiskSubType(@RequestParam(value = "riskClassCode", required = false) String riskClassCode,
                                                    @RequestParam(value = "riskSubType", required = false) String riskSubType) {
        UserEntity user = UserContext.getUser();
        if(VerifyUtils.isEmpty(user)){
            return null;
        }
        return riskService.listRiskSubType(riskClassCode, riskSubType);
    }

    @GetMapping("/listRiskInfoBySubTypeCode")
    @ApiOperation(value = "根据险种编码查询对应的险类信息")
    public List<CgnciRiskSubTypeVO> listRiskInfoBySubTypeCode(@RequestParam(value = "riskSubTypeCodes", required = false) String riskSubTypeCodes) {
        UserEntity user = UserContext.getUser();
        if(VerifyUtils.isEmpty(user)){
            return null;
        }
        return riskService.listRiskInfoBySubTypeCode(riskSubTypeCodes);
    }


}

